package com.hdsx.restful.glzt.roadline.jsdj.rest;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import org.springframework.stereotype.Service;

import com.hdsx.restful.glzt.roadline.jsdj.bean.Jsdj;
import com.hdsx.restful.glzt.roadline.jsdj.service.JsdjService;
import com.hdsx.restful.util.CheckEmpty;
import com.hdsx.restful.util.EasyUI;

@Path("/jsdj")
@Service
public class JsdjRestServer {
	
	@Resource(name = "jsdjServiceImpl")
	private JsdjService service;

	/**
	 * Gets the list.
	 * http://192.168.0.103:8080/restful/rest/jsdj/list?lxdm=H108&page=0&rows=10
	 * @param
	 * @param
	 * @return the list
	 */
	@GET
	@Path("/list")
	@Produces(MediaType.APPLICATION_JSON)
	public EasyUI<Jsdj> queryList(@QueryParam("lxdm") String lxdm,@QueryParam("page") int page,@QueryParam("rows") int rows) {
		EasyUI<Jsdj> uiPage = new EasyUI<Jsdj>(page, rows);
		int count =service.queryCountByParameter(lxdm);
		List<Jsdj> servicefws= service.queryByParameter(lxdm,uiPage.getBegin(),uiPage.getEnd());
		uiPage.setTotal(count);
		uiPage.setRows(servicefws);
		return uiPage;
	}
	
	@GET
	@Path("/queryJsdjString")
	@Produces(MediaType.APPLICATION_JSON)
	public String queryJsdjString(@QueryParam("id") String id)
	{
		return service.queryJsdjString(id);
	}
	

	@GET
	@Path("/queryGsgl")
	@Produces(MediaType.TEXT_PLAIN)
	public EasyUI<Jsdj> queryGsgl(@QueryParam("lxdm") String lxdm,@QueryParam("lxmc") String lxmc,
			@QueryParam("page") int page,@QueryParam("rows") int rows){
		
		EasyUI<Jsdj> uiPage = new EasyUI<Jsdj>(page, rows);
		int count =service.queryCountGsgl(lxdm);
		List<Jsdj> lists=service.queryGsgl(lxdm,lxmc,uiPage.getBegin(),uiPage.getEnd());
		uiPage.setTotal(count);
		uiPage.setRows(lists);
		return uiPage;
	}
	
	@GET
	@Path("/detail")
	@Produces(MediaType.APPLICATION_JSON)
	public EasyUI<Jsdj> detail(@QueryParam("xzqhbm") String xzqhbm,@QueryParam("jsdj")String jsdj_string,@QueryParam("xzdj")String xzdj_string,@QueryParam("page") int page,@QueryParam("rows") int rows){
		xzqhbm = CheckEmpty.subXzqhbm(xzqhbm);
		EasyUI<Jsdj> easyUI=new EasyUI<Jsdj>(page,rows);
		Map<String,Object> map = easyUI.getParameter();
		try{
			map.put("jsdj", Integer.parseInt(jsdj_string));
		}catch (Exception e){
			System.out.println("不是技术等级分类！");
		}
		try{
			map.put("xzdj", Integer.parseInt(xzdj_string));
		}catch (Exception e){
			System.out.println("不是行政等级分类！");
		}
		map.put("xzqhbm", xzqhbm);
		List<Jsdj> lists=service.queryDetail(map);
		int total = service.countDetail(map);
		easyUI.setRows(lists);
		easyUI.setTotal(total);
		return easyUI;
	}
	
}
